package it.asvp.asvp_portal.data.dao.impl;


import it.asvp.asvp_portal.data.dao.ArtPictureDao;
import it.asvp.asvp_portal.data.entity.art.ArtPicture;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ArtPictureDaoImpl implements ArtPictureDao{

	private static final Log log = LogFactory.getLog(ArtPictureDaoImpl.class);

	@Autowired
	SessionFactory sessionFactory;

	public Long persist(ArtPicture transientInstance) {
		log.debug("persisting ArtPicture instance");
	    Long id;
	    
		try {
			id=(Long)sessionFactory.getCurrentSession().save(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
		return id;
	}

	public void delete(ArtPicture persistentInstance) {
		log.debug("deleting ArtPicture instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ArtPicture merge(ArtPicture detachedInstance) {
		log.debug("merging ArtPicture instance");
		try {
			ArtPicture result = (ArtPicture) sessionFactory.getCurrentSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public ArtPicture findById(java.lang.Long id) {
		log.debug("getting ArtPicture instance with id: " + id);
		try {
			ArtPicture instance = (ArtPicture) sessionFactory
					.getCurrentSession()
					.get("it.asvp.asvp_portal.data.dao.generator.ArtPicture",
							id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

}
